var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var a in e) e.hasOwnProperty(a) && (t[a] = e[a]);
    })(t, e);
}, function(t, e) {
    function a() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (a.prototype = e.prototype, 
    new a());
}), a = this && this.__decorate || function(t, e, a, n) {
    var i, o = arguments.length, r = o < 3 ? e : null === n ? n = Object.getOwnPropertyDescriptor(e, a) : n;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, a, n); else for (var c = t.length - 1; 0 <= c; c--) (i = t[c]) && (r = (o < 3 ? i(r) : 3 < o ? i(e, a, r) : i(e, a)) || r);
    return 3 < o && r && Object.defineProperty(e, a, r), r;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("Global"), s = e("PrefabView"), c = e("AudioManager"), l = e("DrawItemView"), d = e("DrawBigItemView"), u = e("DrawPetConfig"), p = e("DrawSkinConfig"), h = e("MyButton"), f = e("NativeAdTimeView"), g = e("GameConfig"), m = e("GameData"), y = e("PetManager"), v = e("ActivityManager"), w = (e("DataManager"), 
e("WebManager")), b = e("LoadManager"), P = e("UIManager"), I = e("DrawManager"), G = e("FSVideoAdManager"), _ = e("VideoAdManager"), A = cc._decorator, k = A.ccclass, M = A.property, C = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.gunToggle = null, t.petLayout = null, t.personLayout = null, t.gunLayout = null, 
        t.normalLabLayout = null, t.eventLabLayout = null, t.mask = null, t.lightLeft = null, 
        t.lightRight = null, t.countLabel = null, t.drawLabel = null, t.costLabel = null, 
        t.drawBtn = null, t.item = null, t.bigItem = null, t.myButton = null, t.points = [ cc.v2(-256, 160), cc.v2(-128, 160), cc.v2(0, 160), cc.v2(128, 160), cc.v2(256, 160), cc.v2(235, 0), cc.v2(256, -160), cc.v2(128, -160), cc.v2(0, -160), cc.v2(-128, -160), cc.v2(-256, -160), cc.v2(-235, 0) ], 
        t.lastPetIdx = 0, t.lastPersonIdx = 0, t.lastGunIdx = 0, t.diamond = 1e3, t.piece = 300, 
        t.drawType = "pet", t.petItems = [], t.personItems = [], t.gunItems = [], t;
    }
    return i(t, e), t.prototype.onLoad = function() {
        this.gunToggle.active = !(!v.ActivityManager.getInstance().checkActivity(v.ActivityType.CHRISTMAS) && !v.ActivityManager.getInstance().checkActivity(v.ActivityType.NEWYEAR));
    }, t.prototype.onEnable = function() {
        cc.systemEvent.on(this.text, this.callback, this);
    }, t.prototype.onDisable = function() {
        cc.systemEvent.off(this.text, this.callback, this), G.default.getInstance().doShowFSVideo(this.text), 
        e.prototype.onDisable.call(this);
    }, t.prototype.onToggle = function(t) {
        c.default.getInstance().playAudio("按钮2");
        t = t.node.getSiblingIndex();
        this.showToggle(t);
    }, t.prototype.showToggle = function(t) {
        0 == t ? (this.drawType = "pet", this.petLayout.active = !0, this.personLayout.active = !1, 
        this.gunLayout.active = !1, this.normalLabLayout.active = !0, this.eventLabLayout.active = !1) : 1 == t ? (this.drawType = "skin", 
        this.petLayout.active = !1, this.personLayout.active = !0, this.gunLayout.active = !1, 
        this.normalLabLayout.active = !0, this.eventLabLayout.active = !1) : (this.drawType = "gun", 
        this.petLayout.active = !1, this.personLayout.active = !1, this.gunLayout.active = !0, 
        this.normalLabLayout.active = !1, this.eventLabLayout.active = !0), this.refresh(), 
        cc.systemEvent.emit("draw_loaded");
    }, t.prototype.callback = function() {
        "gun" == this.drawType && (v.ActivityManager.getInstance().checkActivity(v.ActivityType.NEWYEAR) ? m.GD.newYearDrawCount++ : v.ActivityManager.getInstance().checkActivity(v.ActivityType.CHRISTMAS) && m.GD.christmasDrawCount++), 
        this.doDraw();
    }, t.prototype.onClickDraw = function() {
        c.default.getInstance().playAudio("按钮2"), w.default.getInstance().sentLog("点击抽奖界面抽奖按键"), 
        "pet" == this.drawType ? m.GD.piece < this.piece ? m.GD.pieceCount < g.GC.maxPieceCount && r.G.platform != r.Platform.XiaoDu ? P.default.getInstance().loadPopPnl("piece", {
            num: g.GC.pieceNum,
            view: this
        }) : P.default.getInstance().showToast({
            str: "碎片不足"
        }) : (m.GD.piece -= this.piece, this.doDraw()) : "skin" == this.drawType ? m.GD.diamond < this.diamond ? r.G.platform != r.Platform.XiaoDu ? P.default.getInstance().loadPopPnl("diamond", {
            num: 100,
            view: this
        }) : P.default.getInstance().showToast({
            str: "钻石不足"
        }) : (m.GD.diamond -= this.diamond, this.doDraw()) : (v.ActivityManager.getInstance().checkActivity(v.ActivityType.NEWYEAR) ? (m.GD.newYearDrawTotal--, 
        m.GD.newYearDrawCount++) : v.ActivityManager.getInstance().checkActivity(v.ActivityType.CHRISTMAS) && (m.GD.christmasDrawTotal--, 
        m.GD.christmasDrawCount++), this.doDraw());
    }, t.prototype.onClickBack = function() {
        c.default.getInstance().playAudio("按钮2"), w.default.getInstance().sentLog("点击抽奖界面返回按键"), 
        this.hidePnl();
    }, t.prototype.start = function() {
        this.init();
    }, t.prototype.init = function() {
        var t = this;
        this.initPet().then(function() {
            cc.isValid(t) && t.initPerson();
        }).then(function() {
            cc.isValid(t) && t.initGun();
        });
    }, t.prototype.initPet = function() {
        var n = this;
        return new Promise(function(e, a) {
            u.DPC.isLoad ? (n.initPetByLocal(), n.refresh(), cc.systemEvent.emit("draw_loaded"), 
            e()) : w.default.getInstance().getLuckDrawConfig({
                drawType: "pet",
                success: function(t) {
                    0 == t.data.code && u.DPC.init(t.data.data), cc.isValid(n) ? (n.initPetByLocal(), 
                    n.refresh(), cc.systemEvent.emit("draw_loaded"), y.default.getInstance().isHas(3) || 100 != u.DPC.totalDrawNum || r.G.queue.push({
                        name: "draw_reward",
                        type: 2,
                        data: I.default.getInstance().doDraw({
                            type: r.RewardType.ANGLE,
                            weight: 1,
                            data: {
                                idx: 300
                            }
                        })
                    }), e()) : a();
                },
                fail: function() {
                    cc.isValid(n) ? (n.initPetByLocal(), n.refresh(), cc.systemEvent.emit("draw_loaded"), 
                    e()) : a();
                }
            });
        });
    }, t.prototype.initPerson = function() {
        var n = this;
        return new Promise(function(e, a) {
            p.DSC.isLoad ? (n.initPersonByLocal(), n.refresh(), cc.systemEvent.emit("draw_loaded"), 
            e()) : w.default.getInstance().getLuckDrawConfig({
                drawType: "skin",
                success: function(t) {
                    0 == t.data.code && p.DSC.init(t.data.data), cc.isValid(n) ? (n.initPersonByLocal(), 
                    n.refresh(), cc.systemEvent.emit("draw_loaded"), e()) : a();
                },
                fail: function() {
                    cc.isValid(n) ? (n.initPersonByLocal(), n.refresh(), cc.systemEvent.emit("draw_loaded"), 
                    e()) : a();
                }
            });
        });
    }, t.prototype.initGun = function() {
        var e = this;
        return new Promise(function(t) {
            e.initGunByLocal(), e.refresh(), cc.systemEvent.emit("draw_loaded"), t();
        });
    }, t.prototype.initPetByLocal = function() {
        var i = this;
        g.GC.drawPetConfig.forEach(function(t, e) {
            var a, n;
            0 == t.mode ? ((a = cc.instantiate(i.item.node)).setPosition(i.points[e]), a.parent = i.petLayout, 
            a.active = !0, (n = a.getComponent(l.default)).init(t)) : ((a = cc.instantiate(i.bigItem.node)).setPosition(i.points[e]), 
            a.parent = i.petLayout, a.active = !0, (n = a.getComponent(d.default)).init(t)), 
            i.petItems.push(n);
        });
    }, t.prototype.initPersonByLocal = function() {
        var i = this;
        g.GC.drawPersonConfig.forEach(function(t, e) {
            var a, n;
            0 == t.mode ? ((a = cc.instantiate(i.item.node)).setPosition(i.points[e]), a.parent = i.personLayout, 
            a.active = !0, (n = a.getComponent(l.default)).init(t)) : ((a = cc.instantiate(i.bigItem.node)).setPosition(i.points[e]), 
            a.parent = i.personLayout, a.active = !0, (n = a.getComponent(d.default)).init(t)), 
            i.personItems.push(n);
        });
    }, t.prototype.initGunByLocal = function() {
        var i = this;
        g.GC.drawGunConfig.forEach(function(t, e) {
            var a, n;
            0 == t.mode ? ((a = cc.instantiate(i.item.node)).setPosition(i.points[e]), a.parent = i.gunLayout, 
            a.active = !0, (n = a.getComponent(l.default)).init(t)) : ((a = cc.instantiate(i.bigItem.node)).setPosition(i.points[e]), 
            a.parent = i.gunLayout, a.active = !0, (n = a.getComponent(d.default)).init(t)), 
            i.gunItems.push(n);
        });
    }, t.prototype.doDraw = function() {
        var t, i = this;
        "gun" == this.drawType ? (t = I.default.getInstance().getDraw2(g.GC.drawGunConfig), 
        this.doEffect(t, this.lastGunIdx, function() {
            i.lastGunIdx = t, i.doReward(g.GC.drawGunConfig[t % g.GC.drawGunConfig.length]);
        }), this.refresh()) : w.default.getInstance().luckDraw({
            drawType: this.drawType,
            success: function(t) {
                var e, a, n;
                0 == t.data.code && cc.isValid(i) ? ("pet" == i.drawType ? (u.DPC.init(t.data.data), 
                a = 1 == g.GC.drawTotalDrawNum ? g.GC.drawPetFirstIdx : t.data.data.rewardIdx, i.doEffect(a, i.lastPetIdx, function() {
                    i.lastPetIdx = a, i.doReward(g.GC.drawPetConfig[a % g.GC.drawPetConfig.length]), 
                    g.GC.drawTodayDrawNum == g.GC.drawUpperLimit && cc.systemEvent.emit("draw_finished"), 
                    100 == g.GC.drawTotalDrawNum && r.G.queue.push({
                        name: "draw_reward",
                        type: 2,
                        data: I.default.getInstance().doDraw({
                            type: r.RewardType.ANGLE,
                            weight: 1,
                            data: {
                                idx: 300
                            }
                        })
                    });
                })) : (p.DSC.init(t.data.data), n = 1 == g.GC.drawTotalDrawNum ? g.GC.drawPersonFirstIdx : t.data.data.rewardIdx, 
                i.doEffect(n, i.lastPersonIdx, function() {
                    i.lastPersonIdx = n, i.doReward(g.GC.drawPersonConfig[n % g.GC.drawPersonConfig.length]), 
                    g.GC.drawTodayDrawNum == g.GC.drawUpperLimit && cc.systemEvent.emit("draw_finished"), 
                    100 == g.GC.drawTotalDrawNum && r.G.queue.push({
                        name: "draw_reward",
                        type: 2,
                        data: I.default.getInstance().doDraw({
                            type: r.RewardType.SKIN,
                            weight: 1,
                            data: {
                                idx: 113
                            }
                        })
                    });
                })), i.refresh()) : null === (t = null === (e = GA.PA) || void 0 === e ? void 0 : e.showToast) || void 0 === t || t.call(e, {
                    title: "请求失败",
                    icon: "none"
                });
            }
        });
    }, t.prototype.doEffect = function(t, e, a) {
        var n = this;
        c.default.getInstance().playAudio("抽奖过程"), this.mask.active = !0;
        var t = 12 * GA.rand(4, 6) + t - e + 13, i = e;
        "pet" == this.drawType ? (this.petItems.forEach(function(t) {
            return t.checkMark.active = !1;
        }), cc.tween(this.petLayout).then(cc.repeat(cc.sequence(cc.callFunc(function() {
            b.default.getInstance().loadSpriteFrame({
                url: "image/draw/灯光" + (i % 2 == 0 ? 2 : 1),
                sprite: n.lightLeft
            }), b.default.getInstance().loadSpriteFrame({
                url: "image/draw/灯光" + (i % 2 == 0 ? 1 : 2),
                sprite: n.lightRight
            }), n.petItems[i % n.petItems.length].checkMark.active = !0, 0 < i && (n.petItems[(i - 1) % n.petItems.length].checkMark.active = !1), 
            i++;
        }), cc.delayTime(.1)), t).easing(cc.easeInOut(3))).start()) : "skin" == this.drawType ? (this.personItems.forEach(function(t) {
            return t.checkMark.active = !1;
        }), cc.tween(this.personLayout).then(cc.repeat(cc.sequence(cc.callFunc(function() {
            b.default.getInstance().loadSpriteFrame({
                url: "image/draw/灯光" + (i % 2 == 0 ? 2 : 1),
                sprite: n.lightLeft
            }), b.default.getInstance().loadSpriteFrame({
                url: "image/draw/灯光" + (i % 2 == 0 ? 1 : 2),
                sprite: n.lightRight
            }), n.personItems[i % n.personItems.length].checkMark.active = !0, 0 < i && (n.personItems[(i - 1) % n.personItems.length].checkMark.active = !1), 
            i++;
        }), cc.delayTime(.1)), t).easing(cc.easeInOut(3))).start()) : (this.gunItems.forEach(function(t) {
            return t.checkMark.active = !1;
        }), cc.tween(this.gunLayout).then(cc.repeat(cc.sequence(cc.callFunc(function() {
            b.default.getInstance().loadSpriteFrame({
                url: "image/draw/灯光" + (i % 2 == 0 ? 2 : 1),
                sprite: n.lightLeft
            }), b.default.getInstance().loadSpriteFrame({
                url: "image/draw/灯光" + (i % 2 == 0 ? 1 : 2),
                sprite: n.lightRight
            }), n.gunItems[i % n.gunItems.length].checkMark.active = !0, 0 < i && (n.gunItems[(i - 1) % n.gunItems.length].checkMark.active = !1), 
            i++;
        }), cc.delayTime(.1)), t).easing(cc.easeInOut(3))).start()), this.scheduleOnce(function() {
            n.mask.active = !1, a && a();
        }, .1 * t);
    }, t.prototype.doReward = function(t) {
        P.default.getInstance().loadPopPnl("draw_reward", I.default.getInstance().doDraw(t)), 
        this.refreshItem();
        var e = P.default.getInstance().getPnl("start");
        e && e.personView.init(), "gun" != this.drawType && g.GC.drawTodayDrawNum == g.GC.drawUpperLimit && (null === (e = null === (t = GA.PA) || void 0 === t ? void 0 : t.showToast) || void 0 === e || e.call(t, {
            title: "当前奖池抽奖次数已达上限",
            icon: "none"
        }));
    }, t.prototype.refresh = function() {
        "gun" == this.drawType || ("pet" == this.drawType ? u.DPC.isLoad && (g.GC.drawWorkDayFreeNum = u.DPC.workDayFreeNum, 
        g.GC.drawWorkDayFreeVideoNum = u.DPC.workDayFreeVideoNum, g.GC.drawWorkDayFreeCDSeconds = u.DPC.workDayFreeCDSeconds, 
        g.GC.drawWeekendsFreeNum = u.DPC.weekendsFreeNum, g.GC.drawWeekendsFreeVideoNum = u.DPC.weekendsFreeVideoNum, 
        g.GC.drawWeekendsFreeCDSeconds = u.DPC.weekendsFreeCDSeconds, g.GC.drawCost = u.DPC.drawCost, 
        g.GC.drawUpperLimit = u.DPC.drawUpperLimit, g.GC.drawTotalDrawNum = u.DPC.totalDrawNum, 
        g.GC.drawTodayDrawNum = u.DPC.todayDrawNum, this.diamond = this.piece = u.DPC.drawCost) : "skin" == this.drawType && p.DSC.isLoad && (g.GC.drawWorkDayFreeNum = p.DSC.workDayFreeNum, 
        g.GC.drawWorkDayFreeVideoNum = p.DSC.workDayFreeVideoNum, g.GC.drawWorkDayFreeCDSeconds = p.DSC.workDayFreeCDSeconds, 
        g.GC.drawWeekendsFreeNum = p.DSC.weekendsFreeNum, g.GC.drawWeekendsFreeVideoNum = p.DSC.weekendsFreeVideoNum, 
        g.GC.drawWeekendsFreeCDSeconds = p.DSC.weekendsFreeCDSeconds, g.GC.drawCost = p.DSC.drawCost, 
        g.GC.drawUpperLimit = p.DSC.drawUpperLimit, g.GC.drawTotalDrawNum = p.DSC.totalDrawNum, 
        g.GC.drawTodayDrawNum = p.DSC.todayDrawNum, this.diamond = this.piece = p.DSC.drawCost)), 
        this.refreshBtn(), this.refreshLabel();
    }, t.prototype.refreshBtn = function() {
        var t, e, a, n, i = this;
        "gun" == this.drawType ? (this.drawBtn.node.active = !1, t = v.ActivityManager.getInstance().checkActivity(v.ActivityType.NEWYEAR) ? m.GD.newYearDrawCount : m.GD.christmasDrawCount, 
        n = v.ActivityManager.getInstance().checkActivity(v.ActivityType.NEWYEAR) ? m.GD.newYearDrawTotal : m.GD.christmasDrawTotal, 
        t < 3 ? (this.myButton.node.active = !0, 0 < n ? this.myButton.init(this.text, "免费抽奖", h.BtnBgType.YELLOW, h.BtnIconType.NORMAL) : this.myButton.init(this.text, "免费抽奖", h.BtnBgType.GRAY, h.BtnIconType.NONE), 
        this.myButton.iconSprite.node.active = !1) : (this.myButton.node.active = !0, this.myButton.iconSprite.node.active = !0, 
        _.default.getInstance().check(this.text) ? this.myButton.init(this.text, "免费抽奖", h.BtnBgType.YELLOW, h.BtnIconType.VIDEO) : (this.myButton.init(this.text, "", h.BtnBgType.GRAY, h.BtnIconType.NONE), 
        (a = (e = new cc.Node("timeLabel").addComponent(cc.Label)).node.addComponent(f.default)).tag = PD.tag, 
        a.title = "下次领取：", a.timeLabel = e, a.callback = function() {
            i.myButton.init(i.text, "免费抽奖", h.BtnBgType.YELLOW, h.BtnIconType.VIDEO);
        }, e.node.setPosition(cc.v2(0, -10)), e.node.parent = this.myButton.node, e.fontSize = 25))) : (this.myButton.iconSprite.node.active = !0, 
        "pet" == this.drawType ? b.default.getInstance().loadSpriteFrame({
            url: "image/draw/按键碎片",
            sprite: this.drawBtn.getComponent(cc.Sprite)
        }) : "skin" == this.drawType && b.default.getInstance().loadSpriteFrame({
            url: "image/draw/按键钻石",
            sprite: this.drawBtn.getComponent(cc.Sprite)
        }), g.GC.drawTotalDrawNum < 100 ? (n = new Date(r.G.timestamp).getDay(), g.GC.drawTodayDrawNum < (n < 1 || 5 < n ? g.GC.drawWeekendsFreeNum : g.GC.drawWorkDayFreeNum) ? (this.myButton.node.active = !0, 
        _.default.getInstance().check(this.text) ? this.myButton.init(this.text, "免费抽奖", h.BtnBgType.YELLOW, h.BtnIconType.VIDEO) : (this.myButton.init(this.text, "", h.BtnBgType.GRAY, h.BtnIconType.NONE), 
        (a = (e = new cc.Node("timeLabel").addComponent(cc.Label)).node.addComponent(f.default)).tag = PD.tag, 
        a.title = "下次领取：", a.timeLabel = e, a.callback = function() {
            i.myButton.init(i.text, "免费抽奖", h.BtnBgType.YELLOW, h.BtnIconType.VIDEO);
        }, e.node.setPosition(cc.v2(0, -10)), e.node.parent = this.myButton.node, e.fontSize = 25), 
        this.drawBtn.node.active = !1) : g.GC.drawTodayDrawNum < g.GC.drawUpperLimit ? (this.myButton.node.active = !1, 
        this.drawBtn.node.active = !0, this.drawBtn.interactable = !0) : (this.myButton.node.active = !1, 
        this.drawBtn.node.active = !0, this.drawBtn.interactable = !1)) : (this.myButton.node.active = !1, 
        this.drawBtn.node.active = !0, this.drawBtn.interactable = !1));
    }, t.prototype.refreshLabel = function() {
        "gun" == this.drawType || (g.GC.drawTodayDrawNum < g.GC.drawUpperLimit ? this.costLabel.string = GA.formatNumber(g.GC.drawCost) : this.costLabel.string = "每日限定" + g.GC.drawUpperLimit + "次", 
        this.countLabel.string = g.GC.drawWorkDayFreeNum + "次\n" + g.GC.drawWeekendsFreeNum + "次", 
        this.drawLabel.string = g.GC.drawTotalDrawNum + "/100");
    }, t.prototype.refreshItem = function() {
        var a = this;
        g.GC.drawPetConfig.forEach(function(t, e) {
            e < a.petItems.length && a.petItems[e].refresh(t);
        }), g.GC.drawPersonConfig.forEach(function(t, e) {
            e < a.personItems.length && a.personItems[e].refresh(t);
        });
    }, a([ M(cc.Node) ], t.prototype, "gunToggle", void 0), a([ M(cc.Node) ], t.prototype, "petLayout", void 0), 
    a([ M(cc.Node) ], t.prototype, "personLayout", void 0), a([ M(cc.Node) ], t.prototype, "gunLayout", void 0), 
    a([ M(cc.Node) ], t.prototype, "normalLabLayout", void 0), a([ M(cc.Node) ], t.prototype, "eventLabLayout", void 0), 
    a([ M(cc.Node) ], t.prototype, "mask", void 0), a([ M(cc.Sprite) ], t.prototype, "lightLeft", void 0), 
    a([ M(cc.Sprite) ], t.prototype, "lightRight", void 0), a([ M(cc.Label) ], t.prototype, "countLabel", void 0), 
    a([ M(cc.Label) ], t.prototype, "drawLabel", void 0), a([ M(cc.Label) ], t.prototype, "costLabel", void 0), 
    a([ M(cc.Button) ], t.prototype, "drawBtn", void 0), a([ M(l.default) ], t.prototype, "item", void 0), 
    a([ M(d.default) ], t.prototype, "bigItem", void 0), a([ M(h.default) ], t.prototype, "myButton", void 0), 
    a([ k ], t);
}(s.default);

n.default = C;